using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BOAcademias;
using TOAcademias;

public partial class Inicio : System.Web.UI.Page
{

    TOUsuario toUsuario = new TOUsuario();
    BOAcademia boAcademia = new BOAcademia();

    protected void Page_Load(object sender, EventArgs e)
    {

        

    }
    
    protected void AcademiasGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridView aux = (GridView)sender;
        
     //   Console.WriteLine(aux.SelectedRow.DataItem);
      //  Console.WriteLine(aux.);
      //  Console.WriteLine("Esta es una prueba");
    }
    protected void AcademiasGrid_SelectedIndexChanged(object sender, EventArgs e)
    {
      //  GridView aux = (GridView)sender;
        GridViewRow row = AcademiasGrid.SelectedRow;
        //Console.WriteLine(aux.SelectedRow);
        //  Console.WriteLine(aux.);

        lblCodigo.Text = row.Cells[0].Text;
        txDescripcion.Text = row.Cells[1].Text;
        
        if(row.Cells[2].Text=="ACTIVO"){
            cmbEstado.SelectedIndex=0;
        }else{
            cmbEstado.SelectedIndex = 1;
        
        }

        btnInsertar.Visible = false;
        btnModificar.Visible = true;
        btnCancelar.Visible = true;

    }
    protected void AcademiasGrid_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
       

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TOAcademia toAcademia = new TOAcademia();
        toAcademia.Cod_Academia = lblCodigo.Text;
        toAcademia.Des_Academia = txDescripcion.Text;
        toAcademia.Estado = cmbEstado.SelectedValue;

        boAcademia.modificarAcademia(toAcademia);

        lblCodigo.Text = "";
        txDescripcion.Text = "";
        cmbEstado.SelectedIndex= 0;

        btnCancelar.Visible = false;
        btnModificar.Visible = false;
        btnInsertar.Visible = true;
        AcademiasGrid.DataBind();
    }
    protected void btnInsertar_Click(object sender, EventArgs e)
    {
        
        
        TOAcademia toAcademia = new TOAcademia();
        toAcademia.Des_Academia = txDescripcion.Text;
        toAcademia.Estado = cmbEstado.SelectedValue;

        boAcademia.insertarAcademia(toAcademia);

        AcademiasGrid.DataBind();
        
        lblCodigo.Text = "";
        txDescripcion.Text = "";
        cmbEstado.SelectedIndex = 0;

    }
    protected void btnCancelar_Click(object sender, EventArgs e)
    {
        lblCodigo.Text = "";
        txDescripcion.Text = "";
        cmbEstado.SelectedIndex = 0;

        btnCancelar.Visible = false;
        btnModificar.Visible = false;
        btnInsertar.Visible = true;
    }
}
